package com.fishy.hw3order.controller;


import com.fishy.hw3order.entity.Product;
import com.fishy.hw3order.service.IOrderService;
import com.fishy.hw3order.service.impl.OrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;



/**
 * @author fish66
 */
@RestController
public class OrderController {

    @Autowired
    private IOrderService orderService;



    /**
     * 根据id查询商品
     * @param productId  商品id
     * @return 商品信息
     */
    @RequestMapping(value = "/buy/{productId}", method = RequestMethod.GET)
    public Product findById(@PathVariable Integer productId) {
        //检查有效性
        if (productId == null) {
            throw new IllegalArgumentException("商品ID不能为空");
        }
        Product product = orderService.getProductById(productId);
        System.out.println(product.toString());
        return product;
    }

}
